<template>
	<view>
		<u-search style="background-color:#FFFFFF;" placeholder="请输入安全宣传名称" v-model="keyword" @search="searchnews()">
		</u-search>
		<view class="newstop">
			<u-row>
				<u-col span="3">
					<p style="font-size: 35rpx;font-weight: 700;margin-top: 10rpx;">{{listname}}</p>
				</u-col>
			</u-row>
		</view>

		<view class="wrap">
			<u-row gutter="16" justify="space-between"
				style="background-color:#FFFFFF;border-bottom: 2rpx solid #f2f2f2;padding: 10rpx;"
				v-for="(item,i) in news">
				<u-col span="3" @click="gonews(item.id)">
					<img :src="item.safetyPublicityPic" mode="aspectFill"
						style="width: 200rpx;height: 200rpx;border-radius:20rpx"></img>
				</u-col>
				<u-col span="9" @click="gonews(item.id)">
					<view class="newsname">{{ item.safetyPublicityTitle }}</view>
					<view class="newstime">{{ item.setDate }}</view>
				</u-col>
			</u-row>
			<u-row style="color: #808080;font-size: 40rpx;text-align:center" v-show="end">没有更多新闻了</u-row>
		</view>

	</view>
</template>

<script>
	var timer = null;
	export default {
		data() {
			return {

				listname: '',
				keyword: '',
				/* 数据 */
				news: [],
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					safetyPublicityType: '',
				},
				end: false,
				total: 0,
			}
		},
		onLoad: function(option) {
			this.queryParams.safetyPublicityType = option.listNumber
			this.listname = option.listName
			this.getnews();

		},
		computed: {},
		onShow() {},
		created() {},
		//上滑分页
		onReachBottom: function() {
			var that = this
			if (timer != null) {
				clearTimeout(timer);
			}
			if (this.total <= this.queryParams.pageNum * this.queryParams.pageSize) {
				this.end = true;
			} else {
				timer = setTimeout(function() {
					that.queryParams.pageNum++;
					that.getnews();
				}, 1000);
			}
		},
		methods: {
			getnews() {
				this.$u.api.selectpublictime(this.queryParams).then(res => {
					this.total = res.total;
					for (var i = 0; i < res.rows.length; i++) {
						this.news.push(res.rows[i]);
					}
				})
			},
			openPage(path) {
				this.$u.route({
					url: path
				})
			},

			gonews(num) {
				uni.navigateTo({
					url: '/pages/propaganda/content?newsNumber=' + num,
				})
			},
			searchnews() {
				console.log(this.keyword)
				debugger
				this.$u.api.selectpublictime({
					safetyPublicityType: this.listid,
					safetyPublicityTitle: this.keyword,
				}).then(res => {
					debugger
					this.news = res.rows;
					console.log(this.news);
				})
			}
		}
	}
</script>

<style>
	.item {
		/* margin: 30rpx 0; */
	}

	.wrap {
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top));
		width: 100%;
	}

	/* 数据 */



	.demo-layout {
		height: 80rpx;
		border-radius: 8rpx;
	}

	.bg-purple {
		background: #d3dce6;
	}

	.bg-purple-light {
		background: #e5e9f2;
	}

	.bg-purple-dark {
		background: #99a9bf;
	}

	.newsname {
		font-size: 35rpx;
		margin-top: 30rpx;
		margin-left: 50rpx;
		font-weight: 700;
	}

	.newstime {
		font-size: 30rpx;
		margin-top: 30rpx;
		margin-left: 50rpx;
		color: #7f7f93;
	}

	.newstop {
		background-color: #FFFFFF;
		border: 5rpx solid #dde3ed;
		margin-top: 20rpx;
		height: 80rpx;
	}
</style>
